package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 * createTime：2021/8/17 17:20
 * description：单线程执行task
 */
public class SingleThreadExecutor {
    public static void main(String[] args) throws InterruptedException {


        ExecutorService service = Executors.newSingleThreadExecutor();
        IntStream.range(0, 10)
                .mapToObj(NapTask::new)
                .forEach(service::execute);
        System.out.println("All tasks submitted");
        service.shutdown();
        while (!service.isTerminated()) {
            System.out.println(Thread.currentThread().getName() + " awaiting terminated");
        }
        Thread.sleep(100);
    }
}
